package com.funsport.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.funsport.entity.EventSolitaireParticipant;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 活动接龙参与记录Mapper
 */
@Mapper
public interface EventSolitaireParticipantMapper extends BaseMapper<EventSolitaireParticipant> {
    
    /**
     * 根据接龙ID获取参与者列表
     * 
     * @param solitaireId 接龙ID
     * @return 参与者列表
     */
    @Select("SELECT * FROM event_solitaire_participant WHERE solitaire_id = #{solitaireId} ORDER BY created_at")
    List<EventSolitaireParticipant> selectBySolitaireId(Long solitaireId);
    
    /**
     * 检查用户是否已参与某个接龙
     * 
     * @param solitaireId 接龙ID
     * @param userId 用户ID
     * @return 参与记录数量
     */
    @Select("SELECT COUNT(*) FROM event_solitaire_participant WHERE solitaire_id = #{solitaireId} AND user_id = #{userId}")
    int countByUserAndSolitaire(Long solitaireId, Long userId);
    
    /**
     * 删除用户的某个接龙参与记录
     * 
     * @param solitaireId 接龙ID
     * @param userId 用户ID
     * @return 删除的记录数
     */
    @Select("DELETE FROM event_solitaire_participant WHERE solitaire_id = #{solitaireId} AND user_id = #{userId}")
    int deleteByUserAndSolitaire(Long solitaireId, Long userId);
}

